Function Reference

ObjCreate

Creates a reference to a COM object from the given classname.

ObjCreate ( "classname" [, "servername" [,"username", ["password"]]] )

 

Parameters

Classname The class of the object in the following format:
"appname.objectype"
Servername Optional name of a remote computer from which the
object must be obtained.
Username Optional name of a usercode on the remote computer
You have to enter this in the format "computer\usercode" or
"domain\usercode".
Password Optional password for the usercode on the remote computer.

 

Return Value

Success: Returns an object.
Failure: Returns 0 and sets @error to 1.

 

Remarks

Use ObjCreate() if you want to have a new instance of the referring application.
If you want to connect to an existing process, use ObjGet() instead.

Keep in mind that not all computers have the same set of Objects. So always check for errors after calling ObjCreate().

The following requirements apply if you want to access objects on remote computers:
-The user running the script must have the appropriate permissions.
-The Object on the remote computer must support DCOM (Distributed COM)
-The remote computer must have 'Remote Registry Service' and 'File and Printer sharing' services running.

See the Obj/COM Reference for more information about Objects.

 

Related

GUICtrlCreateObj, IsObj, ObjEvent, ObjGet, ObjName

 

Example


; Example 1
;
; Counting the number of open shell windows

$oShell = ObjCreate("shell.application")    ; Get the Windows Shell Object
$oShellWindows=$oShell.windows          ; Get the collection of open shell Windows

if Isobj($oShellWindows) then

  $string=""                    ; String for displaying purposes

  for $Window in $oShellWindows         ; Count all existing shell windows
    $String = $String & $Window.LocationName & @CRLF
  next

  Msgbox(0,"Shell Windows","You have the following shell windows:" & @CRLF & @CRLF & $String);

endif
exit


; Example 2
;
; Open the MediaPlayer on a REMOTE computer
$oRemoteMedia = ObjCreate("MediaPlayer.MediaPlayer.1","name-of-remote-computer")

If not @error then
    Msgbox(0,"Remote ObjCreate Test","ObjCreate() of a remote Mediaplayer Object successful !")
    $oRemoteMedia.Open( @WindowsDir & "\media\Windows XP Startup.wav")      ; Play sound if file is present
Else
    Msgbox(0,"Remote ObjCreate Test","Failed to open remote Object. Error code: " & hex(@error,8))
Endif